// v8_test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "include/v8.h"
#include <iostream>
#include <string>


#pragma comment(lib, "lib/v8.lib")
#pragma comment(lib, "ws2_32.lib")
#pragma comment(lib, "winmm.lib")

v8::Handle<v8::Value> funcLjw(const v8::Arguments& args)
{
	std::cout<<"ljw is no1"<<std::endl;
	return v8::Null();
}



int _tmain(int argc, _TCHAR* argv[])
{

	v8::HandleScope scopeGlobal;

	v8::Handle<v8::ObjectTemplate> objTemp = v8::ObjectTemplate::New();


	objTemp->Set("ljwFunc", v8::FunctionTemplate::New(funcLjw));


	//v8::Handle<v8::Script> externalScript = v8::Script::Compile()
	


	v8::Handle<v8::Context> ctx = v8::Context::New(NULL, objTemp);
	v8::Context::Scope scope(ctx);
	std::string strInput;

	std::string strSpt = "function abcTst(){return 'abc.html'}";
	v8::Handle<v8::String> v8strSpt = v8::String::New(strSpt.c_str());
	v8::Handle<v8::Script> v8Sciprt = v8::Script::Compile(v8strSpt);
	v8Sciprt->Run();
	
	
	while (getline(std::cin, strInput))
	{
		v8::HandleScope scope;

		v8::Handle<v8::String> strScript = v8::String::New(strInput.c_str(), strInput.length());
		v8::Handle<v8::Script> script = v8::Script::Compile(strScript);
		v8::Local<v8::Value> vl = script->Run();
		v8::String::AsciiValue av(vl);
		std::cout<<*av<<std::endl;		
		
	}

	

	return 0;
}

